//
//  ViewController.m
//  HWLoginModule
//
//  Created by yehuawei on 2018/11/16.
//  Copyright © 2018 postop. All rights reserved.
//

#import "ViewController.h"
#import <KVOController/KVOController.h>
#import "HWLoginModule.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

@property (nonatomic, retain) FBKVOController *kvoController;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self.kvoController observe:[HWLoginModule sharedLoginModule] keyPath:@"isLogin" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSString *,id> * _Nonnull change) {
        BOOL islogin = [change[NSKeyValueChangeNewKey] boolValue];
        if (islogin) {
            self.statusLabel.text = @"已登录";
        } else {
            self.statusLabel.text = @"未登录";
        }
    }];
}
- (IBAction)login:(id)sender {
    [[HWLoginModule sharedLoginModule] loggedInWithAccount:@"adb" password:@"bbb"];
}
- (IBAction)logout:(id)sender {
    [[HWLoginModule sharedLoginModule] logout];
}

-(FBKVOController *)kvoController
{
    if (!_kvoController) {
        _kvoController = [FBKVOController controllerWithObserver:self];
    }
    return _kvoController;
}

@end
